package com.yr.ryjk.department.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yr.ryjk.common.ErrorType;
import com.yr.ryjk.common.Pagination;
import com.yr.ryjk.department.dao.DepartmentMapper;
import com.yr.ryjk.department.entity.Department;
import com.yr.ryjk.util.IDGenerator;
import com.yr.ryjk.util.JSONUtil;

@Service
public class DepartmentService implements IDepartmentService {
	@Autowired
	private DepartmentMapper departmentMapper;
	@Override
	public Department getDepartmentById(String id) 
	{
		return departmentMapper.selectByPrimaryKey(id);
	}

	@Override
	public Map<String, Object> getListOfPage(int pageNo, int pageSize,
			String name,String treatDisease) 
	{
		List<Department> list=departmentMapper.selectOfPage((pageNo-1)*pageSize,pageSize,name,treatDisease);
		int count=departmentMapper.selectCount(name,treatDisease);
		
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("list", list);
		map.put("pagination", new Pagination(pageSize,pageNo,count));
		
		return map;
	}

	@Override
	public Object getListOfApp(String name,String treatDisease) 
	{			
		return departmentMapper.selectOfApp(name, treatDisease);
	}
	
	@Override
	public Map<String, Object> addDepartment(Department department) 
	{
		String id=IDGenerator.gen32UUID();
		department.setId(id);
		departmentMapper.insert(department);
		return JSONUtil.getJSON(ErrorType.SUCCESS);
	}

	@Override
	public Map<String, Object> modifyDepartmentInfo(Department department) 
	{	
		departmentMapper.updateByPrimaryKey(department);
		return JSONUtil.getJSON(ErrorType.SUCCESS);
	}

	@Override
	public List<Department> getAllDepartment()
	{
		return departmentMapper.selectAllDepartment();
	}
	
}
